package com.kanasco.engg.customtag;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import com.kanasco.engg.model.Item;

import bb.access.po.Part;
import bb.common.PartPK;

public class ItemPickTagHandler extends SimpleTagSupport{
	
	private String startIndex;
	private String maxIndex;
	private List list;
	
	

	public ItemPickTagHandler() {
		super();
		// TODO Auto-generated constructor stub
	}

	public void setStartIndex(String startIndex) {
		this.startIndex = startIndex;
	}

	public void setMaxIndex(String maxIndex) {
		this.maxIndex = maxIndex;
	}

	public void setList(List list) {
		this.list = list;
	}

	public void doTag() throws IOException {
		
		JspContext context=getJspContext();
        JspWriter out=context.getOut();


       PageContext page=(PageContext)context;
      HttpServletRequest request=(HttpServletRequest) page.getRequest();
      HttpSession session= request.getSession();

	Integer startIndex=(Integer)session.getAttribute("startIndex");
	
	
	Integer maxIndex=(Integer)session.getAttribute("maxIndex");

	
	List list=(List)session.getAttribute("itemList");
	
	session.setAttribute("list",list);
	
	if(startIndex==null){
		System.out.println("this is if null");
		startIndex=1;
		maxIndex=5;
	
	}
		
	if(startIndex!=null)
	{
		session.setAttribute("previousCount", startIndex);
		
		for(int index=startIndex;index<startIndex+maxIndex;index++){
			Part item = (Part) list.get(index-1);
			PartPK part = item.getPk();
		              String partNumber = part.getPartNumber();
		              String partType = part.getPartType();
		              String revision = item.getRevision();
		              String description=item.getDescription();
		              String productionCode= item.getProductCode();
		              String CommodityCode=item.getCommodityCode();
		             out.println("<table>");
		             
		              
		             
		            
		              out.println("<tr><td>");
		              out.println("<input type=\"radio\" name=\"radio1\" value=\""+partNumber+"\" />");
		              out.println("<td>"+partNumber+"</td>");
		              out.println("<td>"+partType+"</td>");
		              out.println("<td>"+revision+"</td>");
		              out.println("<td>"+CommodityCode+"</td>");
		              out.println("<td>"+productionCode+"</td>");
		              out.println("<td>"+description+"</td>");
		              
		              out.println("</td></tr>");
		              out.println("</table>");
		}

		
	      
	}
}
}
